package com.haozhiyan.zhijian.myDao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.haozhiyan.zhijian.bean.biaoduan.InspectionTwoBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "INSPECTION_TWO_BEAN".
*/
public class InspectionTwoBeanDao extends AbstractDao<InspectionTwoBean, String> {

    public static final String TABLENAME = "INSPECTION_TWO_BEAN";

    /**
     * Properties of entity InspectionTwoBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property SecInsId = new Property(0, String.class, "secInsId", false, "SEC_INS_ID");
        public final static Property SectionId = new Property(1, String.class, "sectionId", false, "SECTION_ID");
        public final static Property InspectionId = new Property(2, String.class, "inspectionId", true, "INSPECTION_ID");
        public final static Property ParentId = new Property(3, String.class, "parentId", false, "PARENT_ID");
        public final static Property InspectionName = new Property(4, String.class, "inspectionName", false, "INSPECTION_NAME");
        public final static Property PartsDivision = new Property(5, String.class, "partsDivision", false, "PARTS_DIVISION");
        public final static Property IsNeedBuild = new Property(6, String.class, "isNeedBuild", false, "IS_NEED_BUILD");
    };

    private Query<InspectionTwoBean> inspectionOneBean_ChildInsQuery;

    public InspectionTwoBeanDao(DaoConfig config) {
        super(config);
    }
    
    public InspectionTwoBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"INSPECTION_TWO_BEAN\" (" + //
                "\"SEC_INS_ID\" TEXT," + // 0: secInsId
                "\"SECTION_ID\" TEXT," + // 1: sectionId
                "\"INSPECTION_ID\" TEXT PRIMARY KEY NOT NULL ," + // 2: inspectionId
                "\"PARENT_ID\" TEXT," + // 3: parentId
                "\"INSPECTION_NAME\" TEXT," + // 4: inspectionName
                "\"PARTS_DIVISION\" TEXT," + // 5: partsDivision
                "\"IS_NEED_BUILD\" TEXT);"); // 6: isNeedBuild
        // Add Indexes
        db.execSQL("CREATE UNIQUE INDEX " + constraint + "IDX_INSPECTION_TWO_BEAN_INSPECTION_ID ON INSPECTION_TWO_BEAN" +
                " (\"INSPECTION_ID\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"INSPECTION_TWO_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, InspectionTwoBean entity) {
        stmt.clearBindings();
 
        String secInsId = entity.getSecInsId();
        if (secInsId != null) {
            stmt.bindString(1, secInsId);
        }
 
        String sectionId = entity.getSectionId();
        if (sectionId != null) {
            stmt.bindString(2, sectionId);
        }
 
        String inspectionId = entity.getInspectionId();
        if (inspectionId != null) {
            stmt.bindString(3, inspectionId);
        }
 
        String parentId = entity.getParentId();
        if (parentId != null) {
            stmt.bindString(4, parentId);
        }
 
        String inspectionName = entity.getInspectionName();
        if (inspectionName != null) {
            stmt.bindString(5, inspectionName);
        }
 
        String partsDivision = entity.getPartsDivision();
        if (partsDivision != null) {
            stmt.bindString(6, partsDivision);
        }
 
        String isNeedBuild = entity.getIsNeedBuild();
        if (isNeedBuild != null) {
            stmt.bindString(7, isNeedBuild);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, InspectionTwoBean entity) {
        stmt.clearBindings();
 
        String secInsId = entity.getSecInsId();
        if (secInsId != null) {
            stmt.bindString(1, secInsId);
        }
 
        String sectionId = entity.getSectionId();
        if (sectionId != null) {
            stmt.bindString(2, sectionId);
        }
 
        String inspectionId = entity.getInspectionId();
        if (inspectionId != null) {
            stmt.bindString(3, inspectionId);
        }
 
        String parentId = entity.getParentId();
        if (parentId != null) {
            stmt.bindString(4, parentId);
        }
 
        String inspectionName = entity.getInspectionName();
        if (inspectionName != null) {
            stmt.bindString(5, inspectionName);
        }
 
        String partsDivision = entity.getPartsDivision();
        if (partsDivision != null) {
            stmt.bindString(6, partsDivision);
        }
 
        String isNeedBuild = entity.getIsNeedBuild();
        if (isNeedBuild != null) {
            stmt.bindString(7, isNeedBuild);
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
    }    

    @Override
    public InspectionTwoBean readEntity(Cursor cursor, int offset) {
        InspectionTwoBean entity = new InspectionTwoBean( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // secInsId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // sectionId
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // inspectionId
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // parentId
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // inspectionName
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // partsDivision
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6) // isNeedBuild
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, InspectionTwoBean entity, int offset) {
        entity.setSecInsId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setSectionId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setInspectionId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setParentId(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setInspectionName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setPartsDivision(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setIsNeedBuild(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
     }
    
    @Override
    protected final String updateKeyAfterInsert(InspectionTwoBean entity, long rowId) {
        return entity.getInspectionId();
    }
    
    @Override
    public String getKey(InspectionTwoBean entity) {
        if(entity != null) {
            return entity.getInspectionId();
        } else {
            return null;
        }
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "childIns" to-many relationship of InspectionOneBean. */
    public List<InspectionTwoBean> _queryInspectionOneBean_ChildIns(String parentId) {
        synchronized (this) {
            if (inspectionOneBean_ChildInsQuery == null) {
                QueryBuilder<InspectionTwoBean> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ParentId.eq(null));
                inspectionOneBean_ChildInsQuery = queryBuilder.build();
            }
        }
        Query<InspectionTwoBean> query = inspectionOneBean_ChildInsQuery.forCurrentThread();
        query.setParameter(0, parentId);
        return query.list();
    }

}
